/***************************************************************
auth_game.auth_new
* @param {*} curlt 游戏验证类型(1-本地,2-cdn)
* @param {*} config 游戏难度(1-简单,2-中等,3-困难)
* @简单难度下时间为5s(2敌)，中等难度下时间为10s(4敌)，困难难度下时间为15s(6敌)
* @已适配手机端
/****************************************************************/
class popup_msg_box {
    constructor() { }
    static yh_popup_new(options) {
        this.defaultOptions = {
            title: 'Tlcputil Authentication System',
            content: '',
            width: '400px',
            height: '300px',
            closable: true
        };
        this.options = {
            ...this.defaultOptions,
            ...options
        };
        return this.init()
    }
    static init() {
        this.mask = document.createElement('div');
        this.mask.className = 'yhpopup-mask';
        this.mask.style.display = 'none';
        document.body.appendChild(this.mask);
        this.popup = document.createElement('div');
        this.popup.className = 'yhpopup-container';
        this.popup.style.width = this.options.width;
        this.popup.style.height = this.options.height;
        this.popup.style.display = 'none';
        document.body.appendChild(this.popup);
        this.titleBar = document.createElement('div');
        this.titleBar.className = 'popup-title-bar';
        this.titleBar.textContent = this.options.title;
        this.popup.appendChild(this.titleBar);
        if (this.options.closable) {
            this.closeBtn = document.createElement('span');
            this.closeBtn.className = 'popup-close-btn';
            this.closeBtn.textContent = '×';
            this.closeBtn.addEventListener('click', () => this.close());
            this.titleBar.appendChild(this.closeBtn)
        }
        this.contentArea = document.createElement('div');
        this.contentArea.className = 'popup-content-area';
        this.contentArea.innerHTML = this.options.content;
        this.popup.appendChild(this.contentArea);
        this.show();
        return this.contentArea
    }
    static show() {
        this.popup.classList.add('slide-in');
        this.popup.style.display = 'block';
        this.mask.style.display = 'block';
        this.mask.style.opacity = 0;
        this.popup.style.opacity = 0;
        setTimeout(() => {
            this.popup.classList.remove('slide-in');
            this.mask.style.opacity = 1;
            this.popup.style.opacity = 1
        }
            , 500)
    }
    static close() {
        this.popup.classList.add('slide-out');
        this.mask.style.opacity = 0;
        this.popup.style.opacity = 0;
        setTimeout(() => {
            this.popup.classList.remove('slide-out');
            this.mask.style.display = 'none';
            this.popup.style.display = 'none';
            this.popup.remove();
            this.mask.remove()
        }
            , 250)
    }
    static showcheckingyes(parentContainerId) {
        const parentContainer = parentContainerId;
        const container = document.createElement('div');
        container.classList.add('popup-dollar-bumuis');
        const loader = document.createElement('div');
        loader.classList.add('yh-checkloader', 'loadding');
        loader.style = "width:150px;height:150px";
        container.appendChild(loader);
        parentContainer.appendChild(container);
        const startTime = Date.now();
        const rotateDuration = 3000;
        const checkDuration = 2000;
        const waitDuration = 2000;
        const checkAndExecute = () => {
            const elapsedTime = Date.now() - startTime;
            if (elapsedTime >= rotateDuration) {
                try {
                    document.querySelector('.font-fucking-text-tlcputill').textContent = "Success!"
                } catch (e) { }
                ; loader.classList.remove('loadding');
                loader.classList.add('check')
            }
            if (elapsedTime < rotateDuration + checkDuration + waitDuration) {
                requestAnimationFrame(checkAndExecute)
            }
        }
            ;
        requestAnimationFrame(checkAndExecute)
    }
    static showcheckingno(parentContainerId) {
        const parentContainer = parentContainerId;
        const container = document.createElement('div');
        container.classList.add('popup-dollar-bumuis');
        const loader = document.createElement('div');
        loader.classList.add('yh-checkloader2', 'loadding');
        loader.style = "width:150px;height:150px";
        container.appendChild(loader);
        parentContainer.appendChild(container);
        const startTime = Date.now();
        const rotateDuration = 3000;
        const crossDuration = 2000;
        const waitDuration = 2000;
        const checkAndExecute = () => {
            const elapsedTime = Date.now() - startTime;
            if (elapsedTime >= rotateDuration) {
                try {
                    document.querySelector('.font-fucking-text-tlcputill').textContent = "Failed! Try Again!"
                } catch (e) { }
                ; loader.classList.remove('loadding');
                loader.classList.add('cross')
            }
            if (elapsedTime < rotateDuration + crossDuration + waitDuration) {
                requestAnimationFrame(checkAndExecute)
            }
        }
            ;
        requestAnimationFrame(checkAndExecute)
    }
}
class auth_game {
    static timevividebug = null;
    constructor() { }
    static besafeinwebsite_delall() {
        document.oncontextmenu = new Function("event.returnValue=false");
        document.onselectstart = new Function("event.returnValue=false");
        document.addEventListener("keydown", function (e) {
            var allowedKeys = ['w', 's', 'a', 'd', ' '];
            for (var i = 48; i <= 57; i++) {
                allowedKeys.push(String.fromCharCode(i))
            }
            for (var i = 65; i <= 90; i++) {
                allowedKeys.push(String.fromCharCode(i))
            }
            for (var i = 97; i <= 122; i++) {
                allowedKeys.push(String.fromCharCode(i))
            }
            if (!allowedKeys.includes(e.key)) {
                e.preventDefault()
            }
        })
    }
    static restoreDefaultBehaviors() {
        console.clear();
        document.oncontextmenu = new Function("event.returnValue=true");
        document.onselectstart = new Function("event.returnValue=true");
        document.removeEventListener("keydown", function (e) {
            var allowedKeys = ['w', 's', 'a', 'd', ' '];
            for (var i = 48; i <= 57; i++) {
                allowedKeys.push(String.fromCharCode(i))
            }
            for (var i = 65; i <= 90; i++) {
                allowedKeys.push(String.fromCharCode(i))
            }
            for (var i = 97; i <= 122; i++) {
                allowedKeys.push(String.fromCharCode(i))
            }
            if (!allowedKeys.includes(e.key)) {
                e.preventDefault()
            }
        })
    }
    static #gameloading(fatuobject, auth_strong) {
        document.addEventListener('keydown', function (event) {
            if (event.key === ' ') {
                event.stopPropagation();
                event.preventDefault()
            }
        });
        return new Promise((resolve, reject) => {
            const config = {
                type: Phaser.AUTO,
                width: 775,
                parent: fatuobject,
                height: 400,
                scene: {
                    preload: preload,
                    create: create,
                    update: update
                }
            };
            const game = new Phaser.Game(config);
            console.clear();
            let player;
            let bullets = [];
            let playerHealth = 100;
            let enemiesKilled = 0;
            let enemyBatch = 0;
            let gameResult = null;
            let enemies = [];
            let timeLimit = 30000;
            let enemyBullets = [];
            const startTime = Date.now();
            let lastFireTime = 0;
            let fireInterval = 650;
            let __emeny_num = 6;
            const bulletSound = new Audio('/yhxplus/stable/authgame/assets/bullet.mp3');
            const bulletSound2 = new Audio('/yhxplus/stable/authgame/assets/bullet2.mp3');
            const hurtsound = new Audio('/yhxplus/stable/authgame/assets/hurt.ogg');
            if (auth_strong === 1) {
                __emeny_num = 2;
                timeLimit = 7000
            } else if (auth_strong === 2) {
                __emeny_num = 4;
                timeLimit = 12000
            } else if (auth_strong === 3) {
                __emeny_num = 6;
                timeLimit = 17000
            }
            function preload() {
                this.load.image('bulletimg', '/yhxplus/stable/authgame/assets/bullet.png')
            }
            function create() {
                player = this.add.rectangle(100, 100, 30, 30, 0x0000ff);
                spawnEnemies.call(this);
                this.enemiesText = this.add.text(10, 10, `已击败敌人:0/总共需要击败敌人:${__emeny_num}`, {
                    fontSize: '16px',
                    fill: '#fff'
                });
                this.healthText = this.add.text(10, 30, `当前血量:100`, {
                    fontSize: '16px',
                    fill: '#fff'
                });
                this.timeText = this.add.text(10, 50, `剩余时间：30`, {
                    fontSize: '16px',
                    fill: '#fff'
                });
                const canvas = game.canvas;
                canvas.focus();
                const canvasStyle = document.defaultView.getComputedStyle(canvas);
                const canvasTop = parseInt(canvasStyle.top, 10);
                canvas.style.top = (canvasTop + 50) + 'px'
            }
            function update() {
                const keys = this.input.keyboard.addKeys({
                    'w': Phaser.Input.Keyboard.KeyCodes.W,
                    's': Phaser.Input.Keyboard.KeyCodes.S,
                    'a': Phaser.Input.Keyboard.KeyCodes.A,
                    'd': Phaser.Input.Keyboard.KeyCodes.D
                });

                let playerDirX = 0;
                let playerDirY = 0;
                if (keys.w.isDown) {
                    playerDirY -= 1
                }
                if (keys.s.isDown) {
                    playerDirY += 1
                }
                if (keys.a.isDown) {
                    playerDirX -= 1
                }
                if (keys.d.isDown) {
                    playerDirX += 1
                }
                const norm = Math.sqrt(playerDirX * playerDirX + playerDirY * playerDirY);
                if (norm !== 0) {
                    playerDirX /= norm;
                    playerDirY /= norm
                }
                if (keys.a.isDown && player.x > 0) {
                    player.x -= 5
                }
                if (keys.d.isDown && player.x < config.width - player.width) {
                    player.x += 5
                }
                if (keys.w.isDown && player.y > 0) {
                    player.y -= 5
                }
                if (keys.s.isDown && player.y < config.height - player.height) {
                    player.y += 5
                }
                const pointer = this.input.activePointer;
                const currentTime = Date.now();
                if (pointer.isDown && pointer.button === 0 && currentTime - lastFireTime >= fireInterval) {
                    firePlayerBullet.call(this);
                    lastFireTime = currentTime
                }
                updateEnemyBullets.call(this);
                updateEnemyBullets2.call(this);
                checkBulletHits.call(this);
                moveEnemies.call(this, playerDirX, playerDirY);
                this.enemiesText.setText(`Defeated:${enemiesKilled}/Total defeats required:${__emeny_num}`);
                this.healthText.setText(`HP:${playerHealth}`);
                if (playerHealth <= 0) {
                    const failText = this.add.text(config.width / 2, config.height / 2, 'The game fails', {
                        fontSize: '64px',
                        fill: '#ff0000',
                        align: 'center'
                    });
                    failText.setOrigin(0.5);
                    this.input.keyboard.removeAllListeners();
                    game.destroy();
                    this.scene.stop('default');
                    setTimeout(() => {
                        var canvasElement = game.canvas;
                        canvasElement.parentNode.removeChild(canvasElement);
                        resolve(false)
                    }
                        , 1000)
                }
                if (enemiesKilled === (__emeny_num)) {
                    const winText = this.add.text(config.width / 2, config.height / 2, 'Game wins', {
                        fontSize: '64px',
                        fill: '#00ff00',
                        align: 'center'
                    });
                    winText.setOrigin(0.5);
                    this.input.keyboard.removeAllListeners();
                    game.destroy();
                    this.scene.stop('default');
                    setTimeout(() => {
                        var canvasElement = game.canvas;
                        canvasElement.parentNode.removeChild(canvasElement);
                        resolve(true)
                    }
                        , 1000)
                }
                const cusrrentTime = Date.now();
                if (currentTime - startTime > timeLimit) {
                    const failText = this.add.text(config.width / 2, config.height / 2, 'Timeout', {
                        fontSize: '64px',
                        fill: '#ff0000',
                        align: 'center'
                    });
                    failText.setOrigin(0.5);
                    this.input.keyboard.removeAllListeners();
                    game.destroy();
                    this.scene.stop('default');
                    setTimeout(() => {
                        var canvasElement = game.canvas;
                        canvasElement.parentNode.removeChild(canvasElement);
                        resolve(false)
                    }
                        , 1000)
                } else {
                    this.timeText.setText(`Time remaining：${Math.floor((timeLimit - (cusrrentTime - startTime)) / 1000)}`)
                }
            }
            function spawnEnemies() {
                const numEnemies = 2;
                const minDistanceFromPlayer = 10;
                const playerCenterX = player.x + player.width / 2;
                const playerCenterY = player.y + player.height / 2;
                let distance = 0;
                for (let i = 0; i < numEnemies; i++) {
                    let x, y;
                    do {
                        x = Phaser.Math.Between(0, config.width);
                        y = Phaser.Math.Between(0, config.height);
                        distance = Math.sqrt((x - playerCenterX) * (x - playerCenterX) + (y - playerCenterY) * (y - playerCenterY))
                    } while (distance < minDistanceFromPlayer);
                    const enemy = this.add.rectangle(x, y, 30, 30, 0xff0000);
                    enemy.health = 50;
                    enemies.push(enemy)
                }
                enemyBatch++
            }
            function firePlayerBullet() {
                const bullet = this.add.image(player.x, player.y, 'bulletimg');
                bullet.visible = true;
                bullets.push(bullet);
                bullet.speed = {
                    x: 0,
                    y: -7
                };
                bulletSound.play()
            }
            function updateEnemyBullets() {
                for (let i = 0; i < enemyBullets.length; i++) {
                    const bullet = enemyBullets[i];
                    bullet.x += bullet.speed.x;
                    bullet.y += bullet.speed.y;
                    if (bullet.x < 0 || bullet.x > config.width || bullet.y < 0 || bullet.y > config.height) {
                        bullet.destroy();
                        enemyBullets.splice(i, 1);
                        i--
                    }
                }
            }
            function updateEnemyBullets2() {
                for (let i = 0; i < bullets.length; i++) {
                    const bullet = bullets[i];
                    bullet.x += bullet.speed.x;
                    bullet.y += bullet.speed.y;
                    if (bullet.x < 0 || bullet.x > config.width || bullet.y < 0 || bullet.y > config.height) {
                        bullet.destroy();
                        bullets.splice(i, 1);
                        i--
                    }
                }
            }
            function checkBulletHits() {
                const teleportProbability = 1;
                for (let i = 0; i < bullets.length; i++) {
                    const bullet = bullets[i];
                    for (let j = 0; j < enemies.length; j++) {
                        const enemy = enemies[j];
                        if (Phaser.Geom.Intersects.RectangleToRectangle(bullet.getBounds(), enemy.getBounds())) {
                            enemy.health -= 25;
                            hurtsound.play();
                            if (enemy.health <= 0) {
                                enemy.destroy();
                                enemies.splice(j, 1);
                                enemiesKilled++;
                                if (enemies.length === 0 && enemyBatch < auth_strong) {
                                    spawnEnemies.call(this)
                                }
                            } else {
                                if (Math.random() < teleportProbability) {
                                    const eventNum = Math.floor(Math.random() * 4);
                                    switch (eventNum) {
                                        case 0:
                                            const playerX = player.x;
                                            const playerY = player.y;
                                            const behindPlayerX = playerX + (player.width / 2 + enemy.width / 2);
                                            const behindPlayerY = playerY;
                                            enemy.x = behindPlayerX;
                                            enemy.y = behindPlayerY;
                                            break;
                                        case 1:
                                            const otherEnemyIndex = Math.floor(Math.random() * enemies.length);
                                            const otherEnemy = enemies[otherEnemyIndex];
                                            enemy.x = otherEnemy.x;
                                            enemy.y = otherEnemy.y;
                                            break;
                                        case 2:
                                            const anotherEnemyIndex = Math.floor(Math.random() * enemies.length);
                                            const anotherEnemy = enemies[anotherEnemyIndex];
                                            anotherEnemy.x = enemy.x;
                                            anotherEnemy.y = enemy.y;
                                            break;
                                        case 3:
                                            if (Math.random() < 0.5) {
                                                if (auth_strong >= 2) {
                                                    spawnEnemies.call(this);
                                                    enemy.destroy();
                                                    enemies.splice(j, 1);
                                                    enemiesKilled++;
                                                    playerHealth += 25;
                                                    __emeny_num += 2;
                                                    timeLimit += 1500;
                                                    fireInterval -= 100;
                                                    auth_strong += 1
                                                }
                                            }
                                    }
                                }
                            }
                            bullet.destroy();
                            bullets.splice(i, 1);
                            i--;
                            break
                        }
                    }
                }
                for (let i = 0; i < enemyBullets.length; i++) {
                    const bullet = enemyBullets[i];
                    if (Phaser.Geom.Intersects.RectangleToRectangle(bullet.getBounds(), player.getBounds())) {
                        playerHealth -= 25;
                        hurtsound.play();
                        bullet.destroy();
                        enemyBullets.splice(i, 1);
                        i--
                    }
                }
            }
            function moveEnemies(playerDirX, playerDirY) {
                const moveChance = 0.02;
                const playerSpeed = 5;
                const sprayRadius = 20;
                const numSprayPoints = 3;
                for (let i = 0; i < enemies.length; i++) {
                    const enemy = enemies[i];
                    if (Math.random() < moveChance) {
                        const predictedPlayerX = player.x + playerDirX * playerSpeed;
                        const predictedPlayerY = player.y + playerDirY * playerSpeed;
                        for (let j = 0; j < numSprayPoints; j++) {
                            const angle = Math.random() * 2 * Math.PI;
                            const offsetX = Math.cos(angle) * Phaser.Math.Between(0, sprayRadius);
                            const offsetY = Math.sin(angle) * Phaser.Math.Between(0, sprayRadius);
                            const sprayPointX = predictedPlayerX + offsetX;
                            const sprayPointY = predictedPlayerY + offsetY;
                            const directionX = (sprayPointX - enemy.x);
                            const directionY = (sprayPointY - enemy.y);
                            const distance = Math.sqrt(directionX * directionX + directionY * directionY);
                            const unitDirectionX = directionX / distance;
                            const unitDirectionY = directionY / distance;
                            enemy.x = Phaser.Math.Clamp(enemy.x + unitDirectionX * 12.5, 0, config.width - enemy.width);
                            enemy.y = Phaser.Math.Clamp(enemy.y + unitDirectionY * 12.5, 0, config.height - enemy.height);
                            const bullet = this.add.rectangle(enemy.x, enemy.y, 5, 5, 0x800080);
                            enemyBullets.push(bullet);
                            bullet.speed = {
                                x: unitDirectionX * 5,
                                y: unitDirectionY * -5
                            };
                            bulletSound2.play()
                        }
                    }
                }
            }
        }
        )
    }
    static auth_yes(popup_cr) {
        return new Promise((resolve, reject) => {
            const target = document;
            const handler = function (event) {
                if (event.key === ' ') {
                    event.stopPropagation();
                    event.preventDefault()
                }
            };
            target.removeEventListener('keydown', handler);
            popup_msg_box.showcheckingyes(popup_cr);
            setTimeout(() => {
                popup_msg_box.close();
                resolve(true)
            }
                , 4750)
        }
        )
    }
    static auth_no(popup_cr) {
        return new Promise((resolve, reject) => {
            const target = document;
            const handler = function (event) {
                if (event.key === ' ') {
                    event.stopPropagation();
                    event.preventDefault()
                }
            };
            target.removeEventListener('keydown', handler);
            popup_msg_box.showcheckingno(popup_cr);
            setTimeout(() => {
                popup_msg_box.close();
                resolve(true)
            }
                , 4750)
        }
        )
    }
    static func_debug_open() {
        auth_game.timevividebug = setInterval(() => {
            (function (a) {
                return (function (a) {
                    return (Function('Function(arguments[0]+"' + a + '")()'))
                }
                )(a)
            }
            )('bugger')('de', 0, 0, (0,
                0))
        }
            , 100)
    }
    static func_debug_open_close() {
        clearInterval(auth_game.timevividebug)
    }
    static safe_beauth() {
        const scriptTags = document.querySelectorAll('script');
        scriptTags.forEach(script => {
            script.remove()
        }
        );
        const linkTags = document.querySelectorAll('link');
        linkTags.forEach(link => {
            if (link.href.endsWith('.js')) {
                link.remove()
            }
        }
        )
    }
    static math_quesion_apper() {
        function removewhite(str) {
            return str.replace(/\s+/g, '');
        }
    
        const operators = ['+', '-', '*', '/'];
        const specialOperators = ['√', '^', 'sin', 'cos', 'tan', 'log'];
        const num1 = math.round(math.random() * 100, 2);
        const num2 = math.round(math.random() * 100, 2);
        const num3 = math.round(math.random() * 100, 2);
        const num4 = math.round(math.random() * 100, 2);
        const operator1 = operators[Math.floor(Math.random() * operators.length)];
        const operator2 = operators[Math.floor(Math.random() * operators.length)];
        const operator3 = operators[Math.floor(Math.random() * operators.length)];
        const useSpecialOperator = Math.random() > 0.5;
        let specialOperator = specialOperators[Math.floor(Math.random() * specialOperators.length)];
        let specialOperand = num1;
        let problem = '';
        let evalProblem = '';
        let difficulty = 0.2; 
        let errorRate = 0.1;  
    
        if (useSpecialOperator) {
            difficulty += 0.2; 
            if (specialOperator === '√') {
                specialOperand = num2;
                const rootNum = math.min(specialOperand, 10);
                problem = `(${specialOperator}${rootNum}) ${operator1} ${num3} ${operator2} ${num4}`;
                evalProblem = `sqrt(${rootNum}) ${operator1} ${num3} ${operator2} ${num4}`;
                difficulty += 0.1; 
            } else if (specialOperator === 'sin' || specialOperator === 'cos' || specialOperator === 'tan') {
                const angle = math.round(math.random() * 2 * Math.PI, 2);
                problem = `${specialOperator}(${angle}) ${operator1} ${num2} ${operator2} ${num3} ${operator3} ${num4}`;
                evalProblem = `${specialOperator}(${angle}) ${operator1} ${num2} ${operator2} ${num3} ${operator3} ${num4}`;
                difficulty += 0.3; 
                errorRate += 0.2; 
            } else if (specialOperator === 'log') {
                const logNum = math.round(math.random() * 99 + 1, 2);
                problem = `log(${logNum}) ${operator1} ${num2} ${operator2} ${num3} ${operator3} ${num4}`;
                evalProblem = `log(${logNum}) ${operator1} ${num2} ${operator2} ${num3} ${operator3} ${num4}`;
                difficulty += 0.3; 
                errorRate += 0.2; 
            } else if (specialOperator === '^') {
                const exponent = math.min(num3, 10);
                problem = `${num1} ${operator1} (${num2}<sup>${exponent}</sup>) ${operator2} ${num4}`;
                evalProblem = `${num1} ${operator1} pow(${num2}, ${exponent}) ${operator2} ${num4}`;
                difficulty += 0.2; 
            }
        } else {
            problem = `${num1} ${operator1} ${num2} ${operator2} ${num3} ${operator3} ${num4}`;
            evalProblem = `${num1} ${operator1} ${num2} ${operator2} ${num3} ${operator3} ${num4}`;
        }
    
        if (operator1 === '/' || operator2 === '/' || operator3 === '/') {
            errorRate += 0.1; 
        }
    
        const realPart = math.round(math.random() * 10, 2);
        const imagPart = math.round(math.random() * 10, 2);
        const complexNum = math.complex(realPart, imagPart);
        const complexOperator = operators[Math.floor(Math.random() * operators.length)];
        problem += ` ${complexOperator} (${realPart} + ${imagPart}i)`;
        evalProblem += ` ${complexOperator} (${realPart} + ${imagPart}i)`;
        difficulty += 0.2; 
        errorRate += 0.2; 
    
        const answer = math.evaluate(evalProblem.replace('√', 'sqrt').replace('^', 'pow'));
        const roundedAnswer = math.round(answer, 0);
    
        return {
            problem: problem,
            answer: removewhite(roundedAnswer.toString()),
            difficulty: Math.min(difficulty, 1), 
            errorRate: Math.min(errorRate, 1)   
        };
    }
    static mobile_phone_auth() {
        return new Promise((resolve, reject) => {
            var question_all = auth_game.math_quesion_apper();
            Swal.fire({
                title: question_all.problem,
                html: `
<input id="youranswer"  style="width:90%;" class="swal2-input" placeholder="The result retains an integer">
<span>Difficulty: ${question_all.difficulty}<br>Error Rate: ${question_all.errorRate * 100}%</span>
`,
                showCancelButton: true,
                confirmButtonText: 'determine',
                cancelButtonText: 'Cancel',
                preConfirm: () => {
                    const youranswer = document.getElementById('youranswer').value;
                    if (!youranswer) {
                        Swal.showValidationMessage('Please fill in both fields');
                    }
                    return {
                        youranswer
                    };
                }
            }).then((result) => {
                if (result.isConfirmed) {
                    const answers = result.value.youranswer;
                    if (answers === question_all.answer) {
                        Swal.fire('Correct answer!', 'You have successfully passed the verification', 'success');
                        setTimeout(() => {
                            resolve(true);
                        }, 2000);

                    } else {
                        Swal.fire('Wrong answer!', 'Please try again', 'error');
                        reject(false);
                    }
                }
            });
        });
    }
    static _feak_loadScript(src) {
        return new Promise((resolve, reject) => {
            const script = document.createElement("script");
            script.src = src;
            script.onload = () => resolve();
            script.onerror = () => reject(new Error(`Failed to load script: ${src}`));
            document.head.appendChild(script);
        });
    }
    static auth_new(config, curlt) {
        return new Promise((resolve, reject) => {
            auth_game.besafeinwebsite_delall();
            auth_game.func_debug_open();
            if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|Mobile)/i)) {
                if (window.Swal && typeof window.Swal.fire === "function" && window.math && typeof window.math.eval === "function") {
                    auth_game.mobile_phone_auth().then(resolve2 => {
                        if (resolve2) {
                            auth_game.restoreDefaultBehaviors();
                            auth_game.func_debug_open_close();
                            resolve(true)
                        } else {
                            reject(false)
                        }
                    });
                } else {
                    Promise.all([
                        auth_game._feak_loadScript("/yhxplus/enviroment/sweetalert/sweetalert2.all.min.js"),
                        auth_game._feak_loadScript("/yhxplus/enviroment/mathjs/lib/browser/math.js")
                    ]).then(() => {
                        auth_game.mobile_phone_auth().then(resolve2 => {
                            if (resolve2) {
                                auth_game.restoreDefaultBehaviors();
                                auth_game.func_debug_open_close();
                                resolve(true);
                            } else {
                                reject(false);
                            }
                        });
                    }).catch(error => {
                        console.error("Loading error", error);
                    });
                }
            } else {
                const popup_cr = popup_msg_box.yh_popup_new({
                    title: 'Tlcputil Authentication System',
                    content: '<div class="font-fucking-text-tlcputill" style="text-align:center;font-size:20px;">Defeat all enemies within the time limit (WSAD move, left mouse button attack)</div>',
                    width: '800px',
                    height: '520px',
                    closable: false
                });
                if (typeof window.Phaser === 'undefined') {
                    const script = document.createElement('script');
                    if (curlt === 1) {
                        script.src = "/yhxplus/enviroment/phaser/phaser.min.js"
                    } else if (curlt === 2) {
                        script.src = "https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.min.js"
                    }
                    script.defer = true;
                    script.onload = function () {
                        auth_game.safe_beauth();
                        auth_game.#gameloading(popup_cr, config).then(resolve2 => {
                            if (resolve2) {
                                auth_game.auth_yes(popup_cr).then(resolve2 => {
                                    auth_game.restoreDefaultBehaviors();
                                    auth_game.func_debug_open_close();
                                    resolve(true)
                                }
                                )
                            } else {
                                auth_game.auth_no(popup_cr).then(resolve2 => {
                                    auth_game.restoreDefaultBehaviors();
                                    auth_game.func_debug_open_close();
                                    resolve(false)
                                }
                                )
                            }
                        }
                        )
                    }
                        ;
                    script.onerror = function () {
                        console.error("Failed to load Phaser from CDN. Switching to local backup.");
                        script.src = "/yhxplus/enviroment/phaser/phaser.min.js";
                        script.onload = function () {
                            auth_game.safe_beauth();
                            auth_game.#gameloading(popup_cr, config).then(resolve2 => {
                                if (resolve2) {
                                    auth_game.auth_yes(popup_cr).then(resolve2 => {
                                        auth_game.restoreDefaultBehaviors();
                                        auth_game.func_debug_open_close();
                                        resolve(true)
                                    }
                                    )
                                } else {
                                    auth_game.auth_no(popup_cr).then(resolve2 => {
                                        auth_game.restoreDefaultBehaviors();
                                        auth_game.func_debug_open_close();
                                        resolve(false)
                                    }
                                    )
                                }
                            }
                            )
                        }
                    }
                        ;
                    document.body.appendChild(script)
                } else {
                    auth_game.#gameloading(popup_cr, config).then(resolve2 => {
                        auth_game.safe_beauth();
                        if (resolve2) {
                            auth_game.auth_yes(popup_cr).then(resolve2 => {
                                auth_game.restoreDefaultBehaviors();
                                auth_game.func_debug_open_close();
                                resolve(true)
                            }
                            )
                        } else {
                            auth_game.auth_no(popup_cr).then(resolve2 => {
                                auth_game.restoreDefaultBehaviors();
                                auth_game.func_debug_open_close();
                                resolve(false)
                            }
                            )
                        }
                    }
                    )
                }
            }
        }
        )
    }
}
